Fix unique_for_<range> validation on partial serializer updates (refs #6341) - #10040
VimalN2005 wants to merge 4 commits into
Conversation
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
I think this also changes full-update semantics. enforce_required_fields() returns for any serializer with an instance, and the fallback-to-instance path below also doesn't check serializer.partial, so a normal partial=False update can omit one or both unique-for fields and silently reuse the old values. Could these shortcuts be gated on serializer.partial so full updates keep the existing required-field behavior?
|
Thanks for the thorough review and catch @sylvesterkaczmarek! You are completely right. I've updated the logic in
All tests and pre-commit checks pass cleanly. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Rechecked 98d9381. Both the required-field bypass and instance fallback are now limited to partial updates, so normal full updates still require both unique-for fields. The three full-update regressions cover each omission shape, and the full CI matrix is green. My concern is resolved.
|
Thank you @sylvesterkaczmarek for the review and approval! @auvipy All requested changes have been addressed, tests are added, and the CI matrix is 100% green whenever you have a moment to take a final look. |
Note: Before submitting a code change, please review our contributing guidelines.
Description
Fixes #6341.
BaseUniqueForValidator(and subclassesUniqueForDateValidator,UniqueForMonthValidator, andUniqueForYearValidator) previously raised a required fieldValidationErroron partial updates (partial=True) wheneverfieldordate_fieldwas omitted from the request payload.Furthermore, if only one of the fields was provided in the partial update, the validator failed because the missing field was not resolved from
serializer.instance.Changes
BaseUniqueForValidator.enforce_required_fieldsto acceptserializer=Noneand bypass requirement checks when updating an existinginstance, matching the design ofUniqueTogetherValidator.BaseUniqueForValidator.__call__to:attrs.serializer.instancewhen only one field is provided.tests/test_validators.pycovering:UniqueForMonthValidatorandUniqueForYearValidatorparity.HiddenFieldwith date constraints.